﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNADota.UI;

namespace XNADota.GamePlay.Ability
{
    public class ItemAbilityObject : AbilityObject
    {
        public string code;

        public float MaxLifeGained = 0;
        public float MaxManaGrained = 0;

        public float AttackBonus = 0;
        public float DefenceBonus = 0;

        public float StrengthBonus = 0;
        public float AgilityBonus = 0;
        public float IntelligenceBonus = 0;

        public float HitPointsRenegeratedPerSecond = 0;
        public float ManaRegeneratedPerSecond = 0;

        public float LifeStolenPerSecond = 0;
        public float AttackSpeedIncrease = 0;
        public float MoveSpeedBonus = 0;

        public ItemAbilityObject(string Id)
            : base(Id)
        {
            ObjectsManager manager = GameplayWorld.Instance.ObjectsManager;

            code = manager.GetFiledValue(EObjectType.AbilityData, Id, "code");
            float dataA1 = this.GetFloat(manager.GetFiledValue(EObjectType.ItemData, Id, "DataA1"));
            float dataB1 = this.GetFloat(manager.GetFiledValue(EObjectType.ItemData, Id, "DataB1"));
            float dataC1 = this.GetFloat(manager.GetFiledValue(EObjectType.ItemData, Id, "DataC1"));

            switch (code)
            {
                case "AIab":
                    AgilityBonus = dataA1;
                    IntelligenceBonus = dataB1;
                    StrengthBonus = dataC1;
                    break;
                case "AIat":
                    AttackBonus = dataA1;
                    break;
                case "AIde":
                    DefenceBonus = dataA1;
                    break;
                case "AIml":
                    MaxLifeGained = dataA1;
                    break;
                case "AIsm":
                    MoveSpeedBonus = dataA1;
                    break;
                case "Arel":
                    HitPointsRenegeratedPerSecond = dataA1;
                    break;
                case "AImm":
                    MaxManaGrained = dataA1;
                    break;
                case "AIas":
                    AttackSpeedIncrease = dataA1;
                    break;
                case "AIrm":
                    ManaRegeneratedPerSecond = dataA1;
                    break;
                default:
                    // do nothing
                    break;
            }
        }
    }

    public class AbilityObject : BasicObject
    {
        public string InterfaceIcon;

        public ItemAbilityObject ItemAbility;
        public MerchantAbilityObject MerchantAbility;

        public AbilityObject(string Id)
            : base(Id, EObjectType.AbilityData)
        {
            ObjectsManager manager = GameplayWorld.Instance.ObjectsManager;

            InterfaceIcon = manager.GetFiledValue(EObjectType.AbilityData, Id, "Art");

            // item ability
            string itemString = GameplayWorld.Instance.ObjectsManager.GetFiledValue(EObjectType.AbilityData, Id, "item");
            if (Convert.ToBoolean(int.Parse(itemString)))
                ItemAbility = new ItemAbilityObject(Id);

            // special ability
            switch (Id)
            {
                case "Apit":
                    MerchantAbility = new MerchantAbilityObject(Id);
                    break;
            }
        }
    }
}
